package com.kawaiior.asoulworld.util;

import net.minecraft.item.ItemStack;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.oredict.OreDictionary;

import java.util.List;

public class ItemHelper {

    public static void compactItemListNoStacksize(List<ItemStack> list)
    {
        for (int i = 0; i < list.size(); i++)
        {
            ItemStack s = list.get(i);
            if (!s.isEmpty())
            {
                for (int j = i + 1; j < list.size(); j++)
                {
                    ItemStack s1 = list.get(j);
                    if (ItemHandlerHelper.canItemStacksStack(s, s1))
                    {
                        s.grow(s1.getCount());
                        list.set(j, ItemStack.EMPTY);
                    }
                }
            }
        }

        list.removeIf(ItemStack::isEmpty);
        list.sort(Comparators.ITEMSTACK_ASCENDING);
    }

    public static boolean areItemStacksEqualIgnoreNBT(ItemStack stack1, ItemStack stack2)
    {
        if (stack1.getItem() != stack2.getItem())
        {
            return false;
        }


        if (stack1.getItemDamage() == OreDictionary.WILDCARD_VALUE || stack2.getItemDamage() == OreDictionary.WILDCARD_VALUE)
        {
            return true;
        }

        return stack1.getItemDamage() == stack2.getItemDamage();
    }

}
